<?php
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\DB;
function getDefault(){
    $arr = DB::table('admin_member')->where('member_id','=',session::get('member_id'))->first();
    $assign = [
        'member_name'=>'',
        'image'=>'',
        'password'=>'',
        'email'=>'',
    ];
    if ($arr){
        $assign['member_name'] = $arr -> member_name;
        $assign['image'] = $arr -> image;
        $assign['password'] = $arr -> password;
        $assign['email'] = $arr -> email;
    }
    return $assign;
}
function objToArr($object) {
    //先编码成json字符串，再解码成数组
    return json_decode(json_encode($object), true);
}
function bar(){
    $arr = objToArr(DB::table('bar')->orderBy('bar_sort','asc')->get(['bar_id','bar_url','bar_name','parent_id','bar_sort']));
    $parent = [];
    $child = [];
    foreach ($arr as $value){
        if ($value['parent_id'] == 0){
            array_push($parent,$value);
        }else{
            $child[$value['parent_id']][] = $value;
        }
    }
    foreach ($parent as &$v){
        $v['_child'] = $child[$v['bar_id']]??[];
    }
    unset($v);
    return $parent;
}
